<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Show detailed information of an event (news).
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.2
 * 
 * 0.2)  Adds the 'LIKE' widget.
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_action.php';
require_once INSTALLDIR . '/lib/slh_util.php';
require_once INSTALLDIR . '/lib/slh_like.php';

require_once INSTALLDIR . '/classes/EventNews.php';


class EventAction extends Action
{
	/**
	 * The EventNews
	 */
	var $eventnews = null;
	
	/**
	 * Poster of the event.
	 */
	var $poster;
	
	/**
	 * The like widget.
	 */
	var $like;
	
	function title()
	{
		return $this->eventnews->title . ' @活动';
	}
	
	function prepare($args)
	{
		parent::prepare($args);
		
		// Parameter from 'get' url
		$news_id = $this->getTrimmedArg('gnews_id');
		
		if ( !is_numeric($news_id)) {
			return false;
		}
		
		// Get the event(news).
		$this->eventnews = EventNews::staticGet('news_id', $news_id);
		if (empty($this->eventnews)) {
			$this->clientError('没有这个活动呃.');
		}
		
		return true;
	}
	
	function handle($args)
	{
		parent::handle($args);

		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			;
		} else {
			// Check if has a posted poster.
			if ( !empty($this->eventnews->poster_id)) {
				// Get the poster.
				$this->poster = Poster::staticGet('id', $this->eventnews->poster_id);
			}

			// LIKE.
			$posturl = null;
			if ( !empty($this->poster)) {
				$posturl = $this->poster->thumbnailurl();
			}
			$this->like = new Like(array('xn_url' => $this->selfUrl(),
										 'xn_showfaces' => 'false',
										 'xn_site_name' => '厦门大学社联会',
										 'xn_title' => $this->eventnews->title,
										 'xn_image' => $posturl,
										 'xn_description' => $this->eventnews->message),
								   $this);
			
			// Increase the 'viewcn' at 'data'.
			$this->eventnews->increaseViewCount();
			
			$this->showPage();
		}
	}
	
	/**
	 * Overriding for LIKE widget.
	 */
	function extraHead()
	{
		$this->like->showMetas();
	}
	
	/**
	 * Overrideing the showInnerContent().
	 */
	function showInnerContent()
	{
		$this->element('h3', null, $this->eventnews->title. ' @活动');
		
		// For LIKE.
		$this->like->show();
		
		$this->elementStart('div', 'cls_div_event');
		if ( !empty($this->poster)) {
			$this->elementStart('div', 'cls_div_eventposter');
			$this->elementStart('a', array('target' => '_blank',
										   'href' => $this->poster->posterurl()));
			$this->element('img', array('src' => $this->poster->thumbnailurl(),
										'max-width' => POSTER_DOUBLE_SIZE,
										'max-height' => POSTER_MAX_HIGHT));
			$this->elementEnd('a');
			$this->elementEnd('div');
		}
		
		$this->raw('<span class="cls_span_eventitem">' .
				   '活动名称: ' .
				   $this->eventnews->title .
				   '</span>');

		$this->elementStart('div', 'cls_div_eventintro');
		$this->raw('<span class="message">' .
				   $this->eventnews->message . 
				   '</span>');
		$this->elementEnd('div');
		
// FIXME: Autocomplete and updating the association_ids in the background.
// FIXME: Get the Associations or hosts?~
		$this->raw('<span class="cls_span_eventitem">' .
				   '活动主办方: ' .
				   $this->eventnews->host .	// or getAssociation()?
				   '</span>');
		
		$this->raw('<span class="cls_span_eventitem">' .
				   '活动地点: ' .
				   $this->eventnews->address .
				   '</span>');
		
		$this->raw('<span class="cls_span_eventitem">' .
				   '开始时间: ' .
				   $this->eventnews->started .
				   $this->eventnews->tagStarttime() .
				   '</span>');

		$this->raw('<span class="cls_span_eventitem">' .
				   '结束时间: ' .
				   $this->eventnews->ended . 
				   '<span class="cls_span_red">' .
				   $this->eventnews->tagEndtime() .
				   '</span>' .
				   '</span>');
				   
		$this->element('h5', null, '活动详细说明: ');
		$this->elementStart('div', 'cls_div_rendered');
		$this->raw(slh_uncompress($this->eventnews->rendered));
		$this->elementEnd('div');
		
		$this->elementEnd('div');
	}
	
// Overrided ends //////////////////////////////////////////////////////////////
	/**
	 * Remove the aside.
	 */
	/*
	function showAsideBlock()
	{}
	*/
}

?>